<template>
  <div class="app-container">
    <!-- 搜索栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="反馈人" prop="technicianName">
        <el-input
          v-model="queryParams.technicianName"
          placeholder="请输入反馈人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="区域名称">
        <el-input
          v-model="queryParams.regionName"
          placeholder="请输入区域名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="门店名称">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入门店名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="反馈时间">
        <el-date-picker
          v-model="paramsTimes"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          @change="getParamsTimes"
        >
        </el-date-picker>
      </el-form-item>


      <el-form-item label="阅读状态" prop="presenter">
                <el-select clearable v-model="queryParams.readStatus" @keyup.enter.native="handleQuery"
                    placeholder="请选择赠送方式">
                    <el-option label="未读" :value="1" />
                    <el-option label="已读" :value="2" />
                </el-select>
            </el-form-item>



      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          v-hasPermi="['business:feedback:query']"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 操作栏 -->
    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:banner:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-close"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:feedback:del']"
          >批量删除</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="bannerList"
      max-height="650px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column
        label="反馈人"
        align="center"
        :show-overflow-tooltip="true"
        prop="feedbackPerson"
      />
      <el-table-column
        label="反馈人电话"
        align="center"
        :show-overflow-tooltip="true"
        prop="feedbackPersonPhone"
      />
      <el-table-column
        label="反馈内容"
        align="center"
        :show-overflow-tooltip="true"
        prop="feedbackValue"
      />

      <el-table-column
        label="反馈时间"
        align="center"
        :show-overflow-tooltip="true"
        prop="createTime"
      />

      <el-table-column
        label="状态"
        align="center"
        :show-overflow-tooltip="true"
        prop="feedbackPersonPhone"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.readStatus==2?'已读':'未读' }}</span>
        </template>

      </el-table-column>
      <!-- <el-table-column label="技师姓名" align="center" prop="technicianName" />
      <el-table-column label="技师号码" align="center" prop="phoneNumber" />
      <el-table-column label="招待热情评分" align="center" prop="enthusiasm" />
      <el-table-column label="技术手法评分" align="center" prop="satisfaction" />
      <el-table-column label="理论知识评分" align="center" prop="profession" />
      <el-table-column label="评价文字" align="center" :show-overflow-tooltip="true" prop="evaluateText" /> -->
      <el-table-column
        label="阅读人"
        align="center"
        :show-overflow-tooltip="true"
        prop="readPersonName"
      />

      <el-table-column
        label="阅读时间"
        align="center"
        :show-overflow-tooltip="true"
        prop="readTime"
      />
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
           <el-button
            size="mini"
            type="text" 
            v-if="scope.row.readStatus!=2"
            icon="el-icon-edit"
            @click="handleRead(scope.row)"
          >阅读</el-button> 
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:feedback:del']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改banner图片对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="区域" prop="regionId">
              <el-select
                clearable
                v-model="form.regionId"
                @change="changeRegion"
                style="width: 260px"
              >
                <el-option
                  v-for="(item, index) of region"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="适用门店" prop="storeId">
              <el-select
                clearable
                v-model="form.storeId"
                @change="changeStore"
                style="width: 260px"
              >
                <el-option
                  v-for="(item, index) of store"
                  :key="index"
                  :label="item.value"
                  :value="item.key"
                  >{{ item.value }}</el-option
                >
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="技师姓名" prop="technicianName">
              <el-input
                v-model="form.technicianName"
                placeholder="请输入技师姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="技师号码" prop="phoneNumber">
              <el-input
                v-model="form.phoneNumber"
                placeholder="请输入技师号码"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="招待热情评分" prop="enthusiasm">
              <el-input
                v-model="form.enthusiasm"
                placeholder="请输入招待热情评分"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="技术手法评分" prop="satisfaction">
              <el-input
                v-model="form.satisfaction"
                placeholder="请输入技术手法评分"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="理论知识评分" prop="profession">
              <el-input
                v-model="form.profession"
                placeholder="请输入理论知识评分"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="评价文字" prop="evaluateText">
              <el-input
                type="textarea"
                v-model="form.evaluateText"
                placeholder="请输入评价文字"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-form-item label="上架" prop="status">
            <el-select clearable v-model="form.status" >
            <el-option v-for="(item,index) of List" :key="index" :label="item.value" :value="item.key">{{item.value}}</el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listfeedback,
  delfeedback,
  listMemberRegion,
  listMemberStore,
  reviewFeedback,
} from "@/api/system/evaluate";
import ScrollPane from '../../layout/components/TagsView/ScrollPane.vue';

export default {
  components: { ScrollPane },
  name: "Banner",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // banner图片表格数据
      bannerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 时间范围
      paramsTimes: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        technicianName: null,
        readStatus:null,
        regionName: null,
        storeName: null,
        startTime: null,
        endTime: null,
        // img: null,
        // showOrNot: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        regionName: [
          { required: true, message: "请选择适用区域", trigger: "blur" },
        ],
        storeName: [
          { required: true, message: "请选择归属门店", trigger: "blur" },
        ],
        technicianName: [
          { required: true, message: "请输入技师姓名", trigger: "blur" },
          {
            min: 1,
            max: 10,
            message: "长度在 1 到 10 个字符",
            trigger: "blur",
          },
        ],
        phoneNumber: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          {
            pattern: /^1[3456789]\d{9}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        enthusiasm: [
          { required: true, message: "请输入招待热情评分", trigger: "blur" },
          {
            pattern: /^([1-5](\.\d+)?|0(\.\d+)?)$/,
            message: "请输入大于等于1小于等于5的数字",
            trigger: "blur",
          },
        ],
        satisfaction: [
          { required: true, message: "请输入理论知识评分", trigger: "blur" },
          {
            pattern: /^([1-5](\.\d+)?|0(\.\d+)?)$/,
            message: "请输入大于等于1小于等于5的数字",
            trigger: "blur",
          },
        ],
        profession: [
          { required: true, message: "请输入招待热情评分", trigger: "blur" },
          {
            pattern: /^([1-5](\.\d+)?|0(\.\d+)?)$/,
            message: "请输入大于等于1小于等于5的数字",
            trigger: "blur",
          },
        ],
        evaluateText: [
          { required: true, message: "请输入技师姓名", trigger: "blur" },
          {
            min: 1,
            max: 30,
            message: "长度在 1 到 30 个字符",
            trigger: "blur",
          },
        ],
      },
      List: [
        {
          key: 1,
          value: "已上架",
        },
        {
          key: 2,
          value: "未上架",
        },
      ],
      region: [],
      store: [],
    };
  },
  created() {
    this.getList();
    this.listregion();
    listMemberStore().then((res) => {
      this.store = res.data.map((rItem) => {
        return {
          key: rItem.id,
          value: rItem.storeName,
        };
      });
    });
  },
  methods: {
    listregion() {
      listMemberRegion().then((res) => {
        this.region = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.regionName,
          };
        });
      });
    },
    changeRegion(value) {
      const selectedOption = this.region.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.regionName = selectedValue;
      listMemberStore({ regionId: value }).then((res) => {
        this.store = res.data.map((rItem) => {
          return {
            key: rItem.id,
            value: rItem.storeName,
          };
        });
      });
    },
    changeStore(value) {
      const selectedOption = this.store.find((item) => item.key === value);
      const selectedKey = selectedOption.key;
      const selectedValue = selectedOption.value;
      this.form.storeName = selectedValue;
    },
    /** 查询banner图片列表 */
    getList() {
      this.loading = true;
      listfeedback(this.queryParams).then((response) => {
        this.bannerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        img: null,
        showOrNot: null,
        createTime: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    // 时间范围选择器
    getParamsTimes() {
      this.queryParams.startTime = this.paramsTimes[0];
      this.queryParams.endTime = this.paramsTimes[1];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.paramsTimes = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加评价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getevaluate(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改评价";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateitemProduct(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBanner(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /**阅读 */
    handleRead(row){
      this.form.id =row.id;
      reviewFeedback(this.form).then((response) => {
              this.$modal.msgSuccess("阅读成功");
              this.open = false;
              this.getList();
            });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除该数据项？")
        .then(function () {
          return delfeedback(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/banner/export",
        {
          ...this.queryParams,
        },
        `banner_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style>
.dialog-footer {
  text-align: center;
}
</style>
